//
//  NEDViewController.m
//  NEDFormView
//
//  Created by 000 on 01/07/2022.
//  Copyright (c) 2022 000. All rights reserved.
//

#import "NEDViewController.h"
#import <NEDStyle/UIColor+NEDStyle.h>
#import <Masonry/Masonry.h>
#import "NEDFormTargetTableView.h"

#import "NEDCollectionTestViewController.h"

@interface NEDViewController ()<NEDFormTableViewProtocol>

@property (retain, nonatomic, readwrite) UITableView * tableView;

@property (retain, nonatomic) NEDFormTargetTableView * targetForm;

@end

@implementation NEDViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"Form tableview list";
    
    WS(weakSelf)
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
    self.tableView.rowHeight = 50;
    self.tableView.tableFooterView = [UIView new];
    self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 20, 13)];
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.estimatedRowHeight = 0;
    self.tableView.contentInset = UIEdgeInsetsZero;
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    /// 注册target 绑定tableview 的delegate和datasource
    NEDFormTargetTableView * targetForm = [[NEDFormTargetTableView alloc] initWithTableView:self.tableView];
    self.targetForm = targetForm;
    // NEDFormItem中rowDataList数据回调主控制器处理
    targetForm.rowDelegate = self;
    
    NEDFormItem * item = NEDFormInitSpace(20);
    [targetForm addOptionItem:item];
    
    item = NEDFormInitTitleCenter(@"标题设置");
    item.layout.showBottomSeparatorLine = YES;
    [targetForm addOptionItem:item];
    
    item = NEDFormInitTitleLeft(@"左边标题").showRightArrow;
    [targetForm addOptionItem:item];
    
    item = NEDFormInitTitleLeftRight(@"左标题", @"右描述");
    [targetForm addOptionItem:item];
    
    //分割线
    item = NEDFormInitSpace(20);
    item.layout.backgroundColor = UIColor.ned_separator.ned_alpha(0.5);
    item.layout.isNotUpdateLayoutFromArrayUnifiedSettings = YES;
    [targetForm addOptionItem:item];
    
    
    
    
    item = NEDFormInitTitleLeft(@"跳转CollectionView 设置他的From").showRightArrow;
    [item setClickBlock:^(NSInteger section, NEDFormSeationView * _Nonnull headerView, __kindof NEDFormItem * _Nonnull passItem) {
        [weakSelf.navigationController pushViewController:[NEDCollectionTestViewController new] animated:YES];
    }];
    [targetForm addOptionItem:item];
    
    
    
    
    
    
    
    targetForm.dataList.form_marginLeft(30).form_marginRight(30);
    
//    item = NEDFormInitTitleLeftOffset(@"左边标题间距", 20);
//    item.layout.showBottomSeparatorLine = YES;
//    [targetForm addOptionItem:item];
//
//    item = NEDFormInit().leftTitle(@"左边标题间距222").marginLeft(40).height(50).showLineBottom;
//    [item showLeftViewBlock:^(UILabel * _Nonnull subView, NEDFormItem * _Nonnull sectionItem, NEDFormContentItem * _Nonnull rowItem) {
//        subView.text = rowItem.content;
//    }];
//    [item configLeftViewBlock:^(UILabel * _Nonnull subView, NEDFormItem * _Nonnull sectionItem, NEDFormContentItem * _Nonnull rowItem) {
//        subView.textColor = UIColor.redColor;
//        subView.font = [UIFont boldSystemFontOfSize:20];
//    }];
//    [targetForm addOptionItem:item];
//
//    item = NEDFormInitSpace(40);
//    item.layout.showBottomSeparatorLine = YES;
//    item.layout.separatorLineColor = UIColor.orangeColor;
//    item.layout.backgroundColor = [UIColor.blueColor colorWithAlphaComponent:0.2];
//    [targetForm addOptionItem:item];
//
//    item = NEDFormInitSpace(20);
//    item.layout.showBottomSeparatorLine = YES;
//    item.layout.separatorLineColor = UIColor.greenColor;
//    item.layout.backgroundColor = [UIColor.blueColor colorWithAlphaComponent:0.2];
//    [targetForm addOptionItem:item];
//
//
    
//    [item.rowDataList addObjectsFromArray:@[@"aaa",@"bbb",@"ccc",@"12222",@"bbb",@"ccc",@"12222",@"bbb",@"ccc",@"12222",@"bbb",@"ccc",@"12222",@"bbb",@"ccc",@"12222"]];

    
    
//    item = NEDFormInitSpace(80);
//    item.layout.showBottomSeparatorLine = YES;
//    item.layout.separatorLineColor = UIColor.greenColor;
//    item.layout.backgroundColor = UIColor.redColor;
//    item.layout.spaceTop = 0;
//    item.layout.spaceTopColor = [UIColor greenColor].ned_alpha(0.1);
//    item.layout.spaceBottom = 20;
//    item.layout.spaceBottomColor = [UIColor greenColor].ned_alpha(0.1);
//    [targetForm addOptionItem:item];
//
//    item = NEDFormInitSpace(50);
//    item.layout.backgroundColor = UIColor.ned_randomColor;
//    item.layout.marginLeft = 20;
//    item.layout.marginRight = 40;
//    [item.rowDataList addObjectsFromArray:@[@"aaa",@"bbb",@"ccc"]];
//    [targetForm addOptionItem:item];
//
//    item = NEDFormInitTitleCenter(@"标题内容");
//    [item setClickBlock:^(NSInteger section, NEDFormSeationView * _Nonnull headerView, __kindof NEDFormItem * _Nonnull passItem) {
//        passItem.content = @"我变了！！！";
//        NSLog(@"点击了%@",passItem.content);
//    }];
//    [item.rowDataList addObjectsFromArray:@[@"aaa",@"bbb",@"ccc",@"12222",@"ccc",@"12222",@"ccc",@"12222",@"ccc",@"12222",@"ccc",@"12222",@"ccc",@"12222",@"ccc",@"12222"]];
//    [targetForm addOptionItem:item];
//
//
//    item = NEDFormInitCustomCenter(^UIView * _Nonnull(__kindof NEDFormItem * _Nonnull passItem) {
//        UILabel * loginLabel = [UILabel new];
//        loginLabel.text = @"登录按钮样式1";
//        loginLabel.backgroundColor = UIColor.ned_randomColor;
//        loginLabel.textAlignment = NSTextAlignmentCenter;
//        loginLabel.textColor = UIColor.ned_white;
//        loginLabel.layer.cornerRadius = 25;
//        loginLabel.layer.masksToBounds = YES;
//        return loginLabel;
//    });
//    [item setClickBlock:^(NSInteger section, NEDFormSeationView * _Nonnull headerView, __kindof NEDFormItem * _Nonnull passItem) {
//        NSLog(@"点击按钮登录样式1");
//    }];
//    [item configLayout:^(NEDFormSectionLayout * _Nonnull layout) {
//        layout.height = 100;
//        layout.marginLeft = 30;
//        layout.marginRight = 30;
//        layout.spaceTop = 40;
//        layout.spaceBottom = 10;
//    }];
//    [targetForm addOptionItem:item];
//
//
//    item = NEDFormInitCustomCenter(^UIView * _Nonnull(__kindof NEDFormItem * _Nonnull passItem) {
//        UILabel * loginLabel = [UILabel new];
//        loginLabel.text = @"按钮样式2";
//        loginLabel.backgroundColor = UIColor.ned_white;
//        loginLabel.textAlignment = NSTextAlignmentCenter;
//        loginLabel.textColor = UIColor.ned_h1;
//        return loginLabel;
//    });
//    [item setClickBlock:^(NSInteger section, NEDFormSeationView * _Nonnull headerView, __kindof NEDFormItem * _Nonnull passItem) {
//        NSLog(@"点击按钮登录样式2");
//    }];
//    [item configLayout:^(NEDFormSectionLayout * _Nonnull layout) {
//        layout.height = 100;
//        layout.spaceTop = 40;
//        layout.spaceBottom = 10;
//        layout.showTopSeparatorLine = YES;
//        layout.showBottomSeparatorLine = YES;
//    }];
//    [targetForm addOptionItem:item];
    
    [targetForm reloadContentView];
}

- (CGFloat)form_tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath sectionItem:(nonnull NEDFormItem *)sectionItem rowItem:(nonnull id)rowItem{
    return 60;
}

-(UITableViewCell *)form_tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath sectionItem:(nonnull NEDFormItem *)sectionItem rowItem:(nonnull id)rowItem{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"cell"];
    }
    cell.textLabel.text = rowItem;
    return cell;
}

-(void)form_tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath sectionItem:(nonnull NEDFormItem *)sectionItem rowItem:(nonnull id)rowItem{
    NSLog(@"点击了 %@",rowItem);
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
